<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */
class KonfirmasiForm extends CFormModel {

    public $no_formulir;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            // username and password are required
            array('no_formulir', 'required'),
            array('no_formulir', 'chekformulir'),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'no_formulir' => 'Nomer formulir',
        );
    }

    /**
     * Authenticates the password.
     * This is the 'authenticate' validator as declared in rules().
     */
    public function chekformulir($attribute, $params) {
        if (!$this->hasErrors()) {
            $model = Pelajar::model()->find('no_formulir = :no_formulir AND confirmasi_status = 0', array(
                'no_formulir' => $this->no_formulir,
            ));
            if ($model == NULL) {
                $this->addError('no_formulir', 'Nomer formulir tidak berlaku');
            }
//            $this->_identity->via = $this->via;
//            if (!$this->_identity->authenticate())
//                $this->addError('password', 'Incorrect username or password.');
        }
    }

    public function proses() {
        $model = Pelajar::model()->find('no_formulir = :no_formulir', array(
            'no_formulir' => $this->no_formulir,
        ));
        $model->confirmasi_status = 1;
        $model->save();
        Yii::app()->user->setFlash('success','konfirmasi anda berhasil, selanjutnya silahkan tunggu konfirmasi dari kami<br /> kami akan mengabari anda 2x24 jam dari sekarang');
    }

}
